package com.scisoft.scan.control.stock;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.scisoft.scan.dy.R;
import com.scisoft.scan.data.stock.StockFlowBean;
import com.squareup.picasso.Picasso;

public class StockFlowActivity extends Activity {

    private ImageView iv_Back; //返回按钮
    private ListView lv_data;
    private TextView tv_partNo;
    private TextView tv_partName;
    private TextView tv_supplierName;
    private TextView tv_ycj;
    private TextView tv_date;
    private TextView tv_depotName;
    private ImageView iv_img;
    private StockFlowBean stockFlowBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar  即隐藏标题栏
        setContentView(R.layout.activity_stock_flow);
        //参数传递
        Intent intent = getIntent();
        //配件库存信息
        stockFlowBean = (StockFlowBean) intent.getSerializableExtra("data");
        //控件初始化
        lv_data = findViewById(R.id.lv_data);
        //返回
        iv_Back = findViewById(R.id.iv_back);
        iv_Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StockFlowActivity.this.finish();
            }
        });
        tv_partNo = findViewById(R.id.tv_partNo);
        tv_partName = findViewById(R.id.tv_partName);
        tv_supplierName = findViewById(R.id.tv_supplierName);
        tv_ycj = findViewById(R.id.tv_ycj);
        tv_date = findViewById(R.id.tv_date);
        tv_depotName = findViewById(R.id.tv_depotName);
        iv_img = findViewById(R.id.iv_img);

        BindData();
    }

    //绑定数据
    private void BindData() {
        //配件信息
        tv_partNo.setText(stockFlowBean.partNo);
        tv_partName.setText(stockFlowBean.partName);
        tv_supplierName.setText(stockFlowBean.manufacturerName);
        String ycj = "1".equals(stockFlowBean.ifYcj) ? "原厂件" : "非原厂件";
        tv_ycj.setText(ycj);
        String date = "期间：" + stockFlowBean.startData + " 至 " + stockFlowBean.stopData;
        tv_date.setText(date);
        tv_depotName.setText(stockFlowBean.depotName);
        if (stockFlowBean.imgUrl != null && !stockFlowBean.imgUrl.equals("")) {
            Picasso.with(this).load(stockFlowBean.imgUrl).into(iv_img);
        } else {
            iv_img.setImageDrawable(getResources().getDrawable(R.drawable.ic_noimage));
        }
        //流水数据
        StockFlowAdapter adapter = new StockFlowAdapter(stockFlowBean.stockFlowDetailBeanList, StockFlowActivity.this);
        lv_data.setAdapter(adapter);
    }

}
